package com.example.testcomposeproject.pages.testRefresh

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.testcomposeproject.MyLogger
import com.example.testcomposeproject.PreViewData
import com.example.testcomposeproject.ui.theme.AppTheme

/**
 * @author: hemin
 * @date: 2024/6/21
 * @Desc: 显示的用了count
 *
 */
@Preview(showBackground = true, device = PreViewData.PreviewPhoneSize)
@Composable
fun PreViewAUI(modifier: Modifier = Modifier) {
    AppTheme {
        AUI(modifier = modifier)

    }
}

/**
 * viewModel 用这个方法
 */
@Composable
fun AScreen(modifier: Modifier = Modifier,clickBack:()->Unit,clickNext:()->Unit) {
    AUI(modifier,clickBack = clickBack,clickNext = clickNext)
}

/**
 * 真正的UI元素
 */
@Composable
fun AUI(modifier: Modifier = Modifier,clickBack: () -> Unit={},clickNext: () -> Unit={}) {

    var clickCount by remember {
        mutableIntStateOf(0)
    }

    MyLogger.hLog().e("AUI")
    Column(
        modifier = Modifier.fillMaxSize(),
        verticalArrangement = androidx.compose.foundation.layout.Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Text(text ="AUI ")

        Text(text =" $clickCount ")

        MyLogger.hLog().e("Column 重组")
        Button(onClick = { clickCount++
            MyLogger.hLog().e("点击")
        }) {
            Text(text = "点击")

            MyLogger.hLog().e("点击Scope重组")
        }

      //注释掉代码只会执行一次
        if (clickCount >=5) {
            Text(text = "点击了 很多 次")
        MyLogger.hLog().e("无关重组")

        }

        Row (modifier = Modifier.fillMaxWidth(), horizontalArrangement = androidx.compose.foundation.layout.Arrangement.SpaceBetween){
            Button(onClick = {
                MyLogger.hLog().e("上一页 点击")
                clickBack()
            }) {
                Text(text = "上一页")

                MyLogger.hLog().e("上一页 点击Scope重组")
            }

            Button(onClick = {
                MyLogger.hLog().e("下一页 点击")
                clickNext()
            }) {
                Text(text = "下一页")

                MyLogger.hLog().e("下一页 点击Scope重组")
            }
        }

        MyLogger.hLog().e("==========================")
    }

}



